/**
 * Project: happyouting-dal-user
 * 
 * File Created at 2009-10-16
 * $Id: IbatisUserDao.java 96 2009-11-10 05:06:12Z worldmaomao $
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.alibaba.happyouting.user.dal.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.happyouting.user.dal.dao.UserDao;
import com.alibaba.happyouting.user.dal.dataobject.User;

/**
 * TODO Comment of IbatisUserDao
 * 
 * @author xingyue.wangxy
 */
public class IbatisUserDao extends SqlMapClientDaoSupport implements UserDao {

    public User getUserById(Long id) {
        return (User) this.getSqlMapClientTemplate().queryForObject("getUserById", id);
    }

    public User getUserByName(String username) {
        return (User) this.getSqlMapClientTemplate().queryForObject("getUserByName", username);
    }

    public void insertUser(User user) {
        this.getSqlMapClientTemplate().insert("insertUser", user);
    }

    public User getAuthenticatedUser(String username, String password) {
        User user = this.getUserByName(username);
        if (user == null) {
            return null;
        }
        if (user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }

    public void deleteUserById(Long id) {

    }

    public void updateUser(User user) {

    }

    public List<User> findUserNotInActivity(Long activityId, String username, Integer start,
                                            Integer size) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("activityId", activityId);
        map.put("username", username);
        map.put("start", start);
        map.put("size", size);
        return this.getSqlMapClientTemplate().queryForList("findUserNotInActivity", map);
    }


    public List<User> findUserInActivity(Long activityId) {
        return this.getSqlMapClientTemplate().queryForList("findUserInActivity", activityId);
    }


    public Integer getCountOfUser() {
        return (Integer)this.getSqlMapClientTemplate().queryForObject("getCountOfUser");
    }


    public Integer getCountOfUserNotInActivity(Long activityId, String username) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("activityId", activityId);
        map.put("username", username);
        return (Integer)this.getSqlMapClientTemplate().queryForObject("getCountOfUserNotInActivity", map);
    }

}
